package com.galgram.project.service.impl;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.galgram.project.domain.FxCourse;
import com.galgram.project.entity.Course;
import com.galgram.project.entity.Order;
import com.galgram.project.mapper.FxCourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.galgram.project.mapper.FxOrderMapper;
import com.galgram.project.domain.FxOrder;
import com.galgram.project.service.IFxOrderService;

/**
 * 订单Service业务层处理
 *
 * @author galgram
 * @date 2024-11-20
 */
@Service
public class FxOrderServiceImpl extends ServiceImpl<FxOrderMapper, FxOrder> implements IFxOrderService {
    @Autowired
    private FxCourseMapper courseMapper;

    @Override
    public List<FxOrder> selectFxOrderList(FxOrder fxOrder) {
        return baseMapper.selectFxOrderList(fxOrder);
    }

    @Override
    public List<Order> getOrderList(Order order) {
        List<Order> orderList = baseMapper.getOrderList(order);
        for (int i = 0; i < orderList.size(); i++) {
            Course course = courseMapper.getCourseById(orderList.get(i).getCourseId());
            orderList.get(i).setCourse(course);
        }
        return orderList;
    }

    @Override
    public List<Order> selectOrderByOrderNumber(Long orderNumber) {
        Order order = baseMapper.selectOrderByOrderNumber(orderNumber);
        Course course = courseMapper.getCourseById(order.getCourseId());
        order.setCourse(course);
        List<Order> orderList = new ArrayList<>();
        orderList.add(order);
        return orderList;
    }

    @Override
    public List<Order> getFinishedOrderList(Order order) {
        List<Order> orderList = baseMapper.getFinishedOrderList(order);
        for (int i = 0; i < orderList.size(); i++) {
            Course course = courseMapper.getCourseById(orderList.get(i).getCourseId());
            orderList.get(i).setCourse(course);
        }
        return orderList;
    }
}
